package ebj.common.java8.function;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;

public class Demo {
    public static void main(String[] args) {
        final List<BigDecimal> prices = Arrays.asList(new BigDecimal("10"), new BigDecimal("30"), new BigDecimal("17"), new BigDecimal("20"), new BigDecimal(
                "15"), new BigDecimal("18"), new BigDecimal("45"), new BigDecimal("12"));
        BigDecimal totalOfDiscountedPrices = BigDecimal.ZERO;
        System.out.println(totalOfDiscountedPrices);
        for (BigDecimal price : prices) {
            if (price.compareTo(BigDecimal.valueOf(20)) > 0) {
                totalOfDiscountedPrices = totalOfDiscountedPrices.add(price.multiply(BigDecimal.valueOf(0.9)));
            }
        }
        System.out.println("totalOfDiscountedPrices = " + totalOfDiscountedPrices);

        final BigDecimal totalPrices = prices.stream().filter(price -> price.compareTo(BigDecimal.valueOf(20)) > 0)
                                .map(price -> price.multiply(BigDecimal.valueOf(0.9)))
                                .reduce(BigDecimal.ZERO, BigDecimal::add);
        System.out.println(totalPrices);
        final List<String> friends = Arrays.asList("Brian", "Nate", "Neal", "Raju", "Sara", "Scott");
        StringBuilder stringBuilder = new StringBuilder();
        friends.forEach(name -> stringBuilder.append(name + ", "));
        friends.forEach(System.out::print);
        System.out.println(stringBuilder.toString());
        
        Long aLong = friends.stream().filter(name -> name.startsWith("N")).count();
        System.out.println(aLong);
        
        Predicate<String> startWithN = name -> name.startsWith("N");
        
        System.out.println(friends.stream().filter(startWithN).count());
        
        System.out.println(String.join(", ",  friends));
        
    }
}
